package com;

/**
 * Test game.
 * @author penguin
 */
import com.iceengine.j3d.main.BasicGame;
import com.iceengine.j3d.main.IceEngine;

import com.iceengine.audio.sound.WaveSound;

import com.iceengine.j3d.camera.*;
import com.iceengine.j3d.models.*;
import com.iceengine.j3d.container.*;
import com.iceengine.j3d.objects.SimpleObject;
import com.iceengine.j3d.particles.ParticleEmitter;

import org.lwjgl.util.vector.Vector3f;

public class TestGame implements BasicGame {
    private BasicCamera BC;
    private Node rootNode;
    public void init()
    {
        IceEngine.initEngine(800, 600, true);
        IceEngine.initGL();

        BC = new BasicCamera();
        BasicCameraControl BCC = new BasicCameraControl(BC);
        IceEngine.addKeyboardEvent(BCC);
        IceEngine.addMouseEvent(BCC);
    }
    public void loadContent()
    {
        IceModel testModel = new IceModel(new Vector3f(1.2f,-0.9f,0f));
        testModel.loadModel("world.ice");

        //Wavefront testWavefront = new Wavefront(new Vector3f(1.2f,0.9f,10));
        //testWavefront.loadModel("test.obj");

        ObjectContainer theWorld = new ObjectContainer(new Vector3f(0,0,-10.0f));

        //SimpleObject testObj = testWavefront.getObject();
        //theWorld.addObject(testObj);

        rootNode = new Node(BC);


        //theWorld.enableLightning();

        float[] ambientLight = { 0.5f, 0.5f, 0.5f, 10.0f };
        float[] diffuseLight = { 1.0f, 1.0f, 1.0f, 1.0f };
        float[] lightPosition = { 0.0f, 0.0f, -2.0f, 1.0f };

        //theWorld.setAmbientLight(ambientLight);
        //theWorld.setDiffuseLight(diffuseLight, lightPosition);

        WaveSound mySound = new WaveSound();
        mySound.init();
        float[] tmp = {0.0f, 0.0f, 0.0f};
        mySound.setListener(tmp, tmp, tmp);
        mySound.loadSound("hell.wav");
        mySound.genSources(tmp, tmp);
        mySound.startPlay();

        ParticleEmitter theEmitter = new ParticleEmitter(new Vector3f(-3,0,4), new Vector3f(1,1,1),new Vector3f(0,-1.9f,0), new org.lwjgl.util.Color(org.lwjgl.util.Color.RED), 1000, 5000, true, true);

        theWorld.addObject(theEmitter);
        theWorld.addObject(testModel.getObject());

        rootNode.addObjectContainer(theWorld);
    }
    public void update()
    {

    }
    public void draw()
    {
        rootNode.draw();
    }
    public boolean isRunning()
    {
        return !IceEngine.isEngineCloseRequested();
    }
}
